﻿using OF.Component.BLL;
using OF.Component.Model;
using OF.Utility;
using OpSystem.common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace OpSystem.manage.authority
{
    public partial class AuthorityUserRole : BasePage
    {
        protected int intUserID
        {
            get
            {
                return RequestUtility.GetQueryInt("id", 1);
            }
        }

        protected string strHtml = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            CheckPageCode("10104");
            if (!IsPostBack)
            {
                RoleBind();
            }
        }

        private void RoleBind()
        {
            IList<AuthorityUserRoleRelaInfo> relaList = AuthorityUserRoleRelaOperate.QueryList(a => a.IsActive == 1 && a.UserID == intUserID);
            IList<AuthorityRoleInfo> list = AuthorityRoleOperate.QueryList(a => a.IsActive == 1);
            var ParentList = from AuthorityRole in list
                             select new { RoleName = AuthorityRole.RoleName, RoleID = AuthorityRole.RoleID };
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("<ul class=\"list-inline\">");
            foreach (var li in ParentList)
            {
                sb.AppendFormat(" <li><input type=\"checkbox\" value=\"{0}\" {2} class=\"ckb\" level=\"1\" name=\"radlst\">{1}</li>", li.RoleID, li.RoleName, checkAuthority(relaList,li.RoleID));
            }
            sb.AppendLine(" </ul>");
            strHtml = sb.ToString();
        }

        private string checkAuthority(IList<AuthorityUserRoleRelaInfo> relaList,int roleId)
        {
            string strRun = "";
            var rli = relaList.Where(a => a.RoleID == roleId).ToList();
           
            if (rli.Count > 0)
            {
                strRun = "checked=\"true\"";
            }

            return strRun;
        }
    }

   
}